package com.itboye.sunsun.luntan;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.sunsun.beans.LuntanForumBean.LuntanForumItemBean;
import com.itboye.sunsunhome.R;

/**
 * Created by fuweiwei on 2016/1/8.
 */
public class OtherAdapter extends BaseAdapter {

	private Context context;
	public List<LuntanForumItemBean> channelList;
	/** 鏄惁鍙 鍦ㄧЩ鍔ㄥ姩鐢诲畬姣曚箣鍓嶄笉鍙锛屽姩鐢诲畬姣曞悗鍙 */
	boolean isVisible = true;
	/** 瑕佸垹闄ょ殑position */
	public int remove_position = -1;
	/** 鏄惁鏄敤鎴烽閬� */
	private boolean isUser = false;

	private boolean isShowDelete = false;// 判断是否显示删除图标跟抖动，true是显示，false是不显示
	// List<LuntanForumItemBean> luntanForumItemBean;

	public OtherAdapter(Context context, List<LuntanForumItemBean> channelList,
			boolean isUser) {
		this.context = context;
		this.channelList = channelList;
		this.isUser = isUser;
	}

	@Override
	public int getCount() {
		return channelList == null ? 0 : channelList.size();
	}

	@Override
	public LuntanForumItemBean getItem(int position) {
		if (channelList != null && channelList.size() != 0) {
			return channelList.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	class ViewHouder {
		TextView item_text;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHouder houder = new ViewHouder();
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.adapter_mygridview_item, null);
			houder.item_text = (TextView) convertView
					.findViewById(R.id.text_item);
			convertView.setTag(houder);
		} else {
			houder = (ViewHouder) convertView.getTag();
		}

		LuntanForumItemBean channel = getItem(position);
		houder.item_text.setText(channel.getName());
		if (isUser) {
			if ((position == 0) || (position == 1)) {
				houder.item_text.setEnabled(false);
			}
		}
		if (!isVisible && (position == -1 + channelList.size())) {
			houder.item_text.setText("");
			houder.item_text.setSelected(true);
			houder.item_text.setEnabled(true);
		}
		if (remove_position == position) {
			houder.item_text.setText("");
		}

		return convertView;
	}

	/** 鑾峰彇棰戦亾鍒楄〃 */
	public List<LuntanForumItemBean> getChannnelLst() {
		return channelList;
	}

	/** 娣诲姞棰戦亾鍒楄〃 */
	public void addItem(LuntanForumItemBean channel) {
		channelList.add(channel);
		notifyDataSetChanged();
	}

	/** 璁剧疆鍒犻櫎鐨刾osition */
	public void setRemove(int position) {
		remove_position = position;
		notifyDataSetChanged();
		// notifyDataSetChanged();
	}

	/** 鍒犻櫎棰戦亾鍒楄〃 */
	public void remove() {
		channelList.remove(remove_position);
		remove_position = -1;
		notifyDataSetChanged();
	}

	/** 璁剧疆棰戦亾鍒楄〃 */
	public void setListDate(List<LuntanForumItemBean> list) {
		channelList = list;
	}

	/** 鑾峰彇鏄惁鍙 */
	public boolean isVisible() {
		return isVisible;
	}

	/** 璁剧疆鏄惁鍙 */
	public void setVisible(boolean visible) {
		isVisible = visible;
	}

}
